extends Node
class_name StateMachine

var currentState:StateBase


func _ready():
	for index in range(get_child_count()):
		var state = get_child(index) as StateBase
		state.stateMachine = self


func process(delta, ownerNode):
	currentState.process(delta, ownerNode)
	
	
func physicsProcess(delta, ownerNode):
	currentState.physicsProcess(delta, ownerNode)
	
	
func changeState(newState, ownerNode):
	if currentState:
		currentState.exitState(ownerNode)
		currentState = null
	
	currentState = get_node(newState) as StateBase
	currentState.enterState(ownerNode)


